import json

from com.lechebang.spider.yiche.GetBrand import *


#brand: data arrays
#table: mysql table name
from com.wushi.utils import dbutil
from com.wushi.yiche.GetBrand import get_brand


def saveData(data, table):
    connection = dbutil.connectDB('lcb_mars_db')
    cursor = connection.cursor()
    sql="insert into test_brand " \
        "values (%d,%s,%s,%s,%d,%d)"
    brand=data[0]
    for brand in data:
        insertsql= "insert into test_brand " \
            "values (%d,'%s','%s','%s',%d,%d)" \
            % (brand['id'],brand['name'],brand['index'],brand['url'],brand['cur'],brand['num'])
    # insertsql="insert into test_brand values (8,'aodi','a','/guangdongaudi/?showtype=1&carids=',0,598)"
        print(insertsql)
        cursor.execute(insertsql)
    # cursor.executemany(sql,data)
    connection.commit()
    cursor.close()
    dbutil.closeDB(connection)


def get_store():
    pass


def start():
    brand =[]
    brand= get_brand()
    if brand==None:
        print("=====>brand get error")
        return
    print('==========%d brands get !!!' % brand.__len__())
    file=open("jiangsu.json", 'w')
    if(file):
        json.dump(brand,file)
    # saveData(brand,'brand')
    
    store=[]
    store=get_store()

if __name__ == '__main__':
    # con=DBUtil.connectDB('yiche')
    # cursor = con.cursor(cursor=pymysql.cursors.DictCursor)   //获取字典型数据
    # cursor.execute('select * from brand')
    # result=cursor.fetchone()
    start()